<!--
 * @Author: windys
 * @Description: 优惠券
 * @Date: 2022-03-07 15:15:32
-->
<template>
  <div>
    <van-nav-bar
      title="优惠券"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
      <van-cell-group inset>
        <van-field
          v-model="redeemCode"
          center
          clearable
          placeholder="请输入优惠券兑换码"
        >
          <template #button>
            <van-button size="small" type="primary" round @click="handleDH"
              >兑换优惠券</van-button
            >
          </template>
        </van-field>
      </van-cell-group>

      <div class="list" v-if="list.length>0">

      </div>
      <div class="no_data" v-else>
         <img src="@/assets/img/nodata.png" alt="" srcset="">
         <p>暂无数据</p>
      </div>
  </div>
</template>



<script >
import { defineComponent, onMounted, ref } from "vue";
import { getCoupon } from "@/api/common";
import { getCouponList } from "@/api/my";
import { useRouter } from "vue-router";
import { Notify, Toast } from "vant";
export default defineComponent({
  setup() {
    onMounted(() => {
      getCouponList({
        pageIndex: 1,
        pageSize: 100,
      });
    });
    const redeemCode = ref("");
    const router = useRouter();
    const list = ref([])
    const onClickLeft = () => {
      router.go(-1);
    };

    const handleDH = async() => {
        const res = await getCoupon({redeemCode:redeemCode.value})
        console.log(res)
        if(typeof res !== 'number'){
            Notify.success('兑换成功,请App使用')
        }
    };
    return {
      list,
      redeemCode,
      onClickLeft,
      handleDH,
    };
  },
});
</script>



<style lang="scss" scoped>
.no_data{
  text-align: center;
  margin-top: 50%;
  img{
    width: 150px;
  }
  p{
    font-size: 18px;
    color: #85d2ff;
  }
}
</style>